﻿package com.d4p.custom.defaultButton
{
	import com.d4p.util.MouseMove;
	import flash.events.MouseEvent;
	
	public class DefaultBtn extends MouseMove
	{
		private static const OVER:String = "over";
		private static const OUT:String  = "out";
		
		public var _id:int;
		
		public function DefaultBtn()
		{
			super();
			this.buttonMode 	= true;
			this.mouseChildren 	= false; 
			this.stop();
			this.addEvent();
		}
		
		public function set init($param:Boolean):void
		{
			if($param){
				addEvent();
			}else{
				removeEvent();
			}
		}
		
		private function removeEvent():void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
			this.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
		}
		
		private function addEvent():void
		{
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
		}
		
		private function onMouseOverHandler(e:MouseEvent):void
		{
			playFrame(OVER);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
		}
		private function onMouseOutHandler(e:MouseEvent):void
		{
			playFrame(OUT);
			this.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
		}
	}
}